import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/store'
import ElementPlus from 'element-plus'
import * as ElementPlusIconsVue from "@element-plus/icons-vue";
import 'element-plus/dist/index.css'
// 引入暗黑模式主题
import 'element-plus/theme-chalk/dark/css-vars.css'

import naive from 'naive-ui'



//全局注册组件
import CategorySelect from './components/CategorySelect.vue'
//全局注册API接口
import API from '@/api'

//注册API接口
const app = createApp(App)
app.use(router)
app.use(store)
app.use(ElementPlus);
// app.use(ElementPlusIconsVue);
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {  //遍历ElementPlusIconsVue对象
  app.component(key, component);
}
// 注册naive-ui
app.use(naive)


//全局注册组件
app.component('CategorySelect', CategorySelect)
//全局注册API接口
app.config.globalProperties.$API = API


app.mount('#app')


// 防抖函数
const debounce = (fn, delay) => {
  let timer
   return (...args) => {
     if (timer) {
       clearTimeout(timer)
     }
     timer = setTimeout(() => {
       fn(...args)
     }, delay)
   }
}
  // 重写ResizeObserver
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver{
   constructor(callback) {
     callback = debounce(callback, 200);
     super(callback);
   }
}
